/*
 * @Author: songliuyang@58.com
 * @Date: 2021-12-14 15:25:02
 * @LastEditors: songliuyang@58.com
 * @LastEditTime: 2021-12-16 14:59:42
 */
var glob = require('glob')
// 生成入口文件配置
const entryConfig = {
  moduleList: [],
  // 开发的页面配置  默认是编译projectList下所有的子项目
  createEntryConfig_dev (projectName) {
    const entryList = {}
    // 获取所有的moduleList
    glob.sync('./src/projectList/**/*').forEach(item => {
      const projectName = item && item.split('/')[3]
      if (!this.moduleList.includes(projectName)) {
        this.moduleList.push(projectName)
      }
    })
    for (const name of this.moduleList) {
      if (projectName === name) {
        entryList[name] = {
          entry: `./src/projectList/${name}/main.js`,
          template: `./src/projectList/${name}/index.html`,
          filename: 'index.html'
        }
      }
    }
    console.log('result', entryList)
    return entryList
  },
  /// 根据传入的参数来决定要打包哪个页面/项目
  createEntryConfig_build (projectName) {
    console.log(projectName, 'projectname')
    const entryList = {}
    entryList[projectName] = {
      entry: `./src/projectList/${projectName}/main.js`,
      template: `./src/projectList/${projectName}/index.html`,
      filename: 'index.html'
    }
    return entryList
  }
}

module.exports = entryConfig
